﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Svr
{
    public static class ExtensionStream
    {
        public static void WriteLine (this Stream ns, string line)
        {
            Write(ns, line + "\n");
        }

        public static void Write (this Stream ns, string line)
        {
            byte[] buff = Encoding.ASCII.GetBytes(line);
            ns.Write(buff, 0, buff.Length);
            ns.Flush();
        }

        public static void Read(this Stream ns, string fixedString)
        {
            byte[] buff = new byte[fixedString.Length];
            ns.Read(buff, 0, buff.Length);
            string stringRead = Encoding.ASCII.GetString(buff);
            if (stringRead.CompareTo(fixedString) != 0)
                throw new Exception("Cadena inesperada");
        }
    }
}
